//
//  FriendNet.m
//  SportSocial
//
//  Created by yull on 14/12/24.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "FriendNet.h"

@implementation FriendNet

+ (AFHTTPRequestOperation *)getFriendListWithSuccessBlock:(httpSuccessBlock)successBlock failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user_friend/list",[self baseUrl]];
    NSDictionary *param = @{@"token":[self token]};
    
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)deleteFriendWithFriendId:(UInt64)friendId successBlock:(httpSuccessBlock)successBlock failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user_friend/delete",[self baseUrl]];
    
    NSDictionary *param =@{@"token":[self token],
                           @"friend_id":[NSNumber numberWithLongLong:friendId]};
    
    AFHTTPRequestOperation *operation = [[self manager] POST:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)applyAddFriendWithUserId:(UInt64)userId
                                        successBlock:(httpSuccessBlock)successBlock
                                           failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user_friend/apply",[self baseUrl]];
    
    NSDictionary *param =@{@"token":[self token],
                           @"friend_id":[NSNumber numberWithLongLong:userId]};
    
    AFHTTPRequestOperation *operation = [[self manager] POST:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)agreeFriendWithUserId:(UInt64)userId
                                          key:(NSString *)key
                                     successBlock:(httpSuccessBlock)successBlock
                                        failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user_friend/agree",[self baseUrl]];
    
    NSDictionary *param =@{@"token":[self token],
                           @"from_user_id":[NSNumber numberWithLongLong:userId],
                           @"key":key};
    
    AFHTTPRequestOperation *operation = [[self manager] POST:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)refuseFriendWithUserId:(UInt64)userId
                                           key:(NSString *)key
                                      successBlock:(httpSuccessBlock)successBlock
                                         failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user_friend/refuse",[self baseUrl]];
    
    NSDictionary *param =@{@"token":[self token],
                           @"from_user_id":[NSNumber numberWithLongLong:userId],
                           @"key":key};
    
    AFHTTPRequestOperation *operation = [[self manager] POST:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}
@end
